package org.lanqiao.taru.dao;


import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.lanqiao.taru.domain.TbUserinfo;
import org.lanqiao.taru.vo.AuthUserVo;
import org.lanqiao.taru.vo.UserinfoVo;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface UserinfoMapper   extends Mapper<TbUserinfo> {



        @Select("SELECT\n" +
                "\tu.id ,\n" +
                "  u.username,\n" +
                "  u.`password`,\n" +
                "u.email,\n" +
                "u.telephone,\n" +
                "u.realname,\n" +
                "u.avatar,\n" +
                "u.create_date  as   createDate \n" +
                "FROM\n" +
                "\ttb_userinfo   u\n" +
                "WHERE\n" +
                "\tusername = #{username}\n" +
                "AND PASSWORD = #{password}")
         TbUserinfo  selectByUsernameAndPassword( AuthUserVo authUser );



    @Select("SELECT\n" +
            "\tu.id ,\n" +
            "  u.username,\n" +
            "  u.`password`,\n" +
            "u.email,\n" +
            "u.telephone,\n" +
            "u.realname,\n" +
            "u.avatar,\n" +
            "u.create_date  as   createDate \n" +
            "FROM\n" +
            "\ttb_userinfo   u\n" +
            "WHERE\n" +
            "\tusername = #{username}\n" +
            "AND PASSWORD = #{password}")
    TbUserinfo  selectByUsernameAndPassword2(@Param("username") String username ,@Param("password")   String password );


    /**
     * 根据用户的id查询用户信息且携带文章
     * @param id
     * @return
     */
    TbUserinfo  selectUserinfoWithArticlesById(Long  id);


    /**
     * 多条件查询
     * @param vo
     * @return
     */
    List<TbUserinfo> getUserinfosByCondition(UserinfoVo  vo);


    /**
     * 批量删除方法
     * @param idList
     */
    void   deleteBatchById(List<Long>   idList);


    /**
     * 加钱
     * @param id
     * @param money
     */

    @Update("update  tb_userinfo  set money  =money + #{money}   where  id=#{id}")
    void    add(@Param("id") Integer  id, @Param("money")  Integer   money);

    /**
     * 减钱
     * @param id
     * @param money
     */
    @Update("update  tb_userinfo  set money  =money  -#{money}   where  id=#{id}")
    void    minus(@Param("id") Integer  id, @Param("money")  Integer   money);

}
